package com.example.votemanage.service.Impl;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.votemanage.entity.Auction;
import com.example.votemanage.entity.AuctionUser;
import com.example.votemanage.exception.ServiceException;
import com.example.votemanage.mapper.AuctionMapper;
import com.example.votemanage.mapper.AuctionUserMapper;
import com.example.votemanage.service.AuctionService;
import com.example.votemanage.service.AuctionUserService;
import com.example.votemanage.utils.TokenUtils;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AuctionUserServiceImpl  extends ServiceImpl<AuctionUserMapper, AuctionUser> implements AuctionUserService {

    @SneakyThrows
    public AuctionUser login(AuctionUser user){
        // 查询数据库中是否存在该用户
        AuctionUser dbUser = baseMapper.selectname(user.getUserName());
        if (dbUser == null) {
            // 抛出一个自定义的异常
            throw new ServiceException("用户名或密码错误");
        }
        String token= TokenUtils.createToken(dbUser.getUserName().toString(),dbUser.getUserPassword());
        dbUser.setToken(token);
        return dbUser;
    }
}